package com.bit.example.principle.component;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

//@Component
public class BeanLifeComponent implements BeanNameAware {

    private DogComponent dogComponent;

    public BeanLifeComponent() {
        System.out.println("执行构造方法");
    }

    @Autowired
    public void setDogComponent(DogComponent dogComponent) {
        this.dogComponent = dogComponent;
        System.out.println("执行属性赋值");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("执行BeanNameAware, beanName:"+ name);
    }

    @PostConstruct
    public void init(){
        System.out.println("执行初始化方法");
    }

    public void  use(){
        System.out.println("使用bean, 执行use 方法");
    }

    @PreDestroy
    public void destroy(){
        System.out.println("销毁Bean");
    }
}
